﻿using System;

namespace NDBGen.Descriptors.Tables.Tokens
{
    public abstract class TableTokenDescriptorBase : ITableTokenDescriptor
    {
        protected abstract Char Token { get; }

        public String TableName { get; private set; }

        protected Boolean InitCalled { get; set; }

        protected virtual void Init(String tableName)
        {
            this.TableName = tableName;
        }

        void ITableTokenDescriptor.Init(String tableName)
        {
            this.Init(tableName);
        }

        Char ITokenDescriptor.Token { get { return this.Token; } }

        public override String ToString()
        {
            return this.Token.ToString();
        }

        public override Boolean Equals(Object obj)
        {
            var that = obj as TableTokenDescriptorBase;
            if (that == null) return false;
            else
            {
                var thisType = this.GetType();
                var thatType = that.GetType();
                return 
                    thisType == thatType &&
                    this.TableName == that.TableName;
            }
        }

        public override Int32 GetHashCode()
        {
            return
                this.GetType().GetHashCode() ^
                this.Token.GetHashCode() ^
                this.TableName.GetHashCode();
        }
    }
}
